//table头信息 不变
var cr_columnData = [
    {"Width": "12%", "ColumnName": "客户Id"},
    {"Width": "13%", "ColumnName": "客户名称"},
    {"Width": "12%", "ColumnName": "记录时间"},
    {"Width": "14%", "ColumnName": "下次回访时间"},
    {"Width": "12%", "ColumnName": "联系人"},
    {"Width": "13%", "ColumnName": "手机号"},
    {"Width": "12%", "ColumnName": "记录内容"},
    {"Width": "12%", "ColumnName": "操作"}
];

//操作按钮 不变
var cr_operateHtml = "<div class='form-inline'>" +
    " <button type='button' class='btn btn-primary innerButtons'  value='view'>查看</button>" +
    "</div>";


//用户管理分页函数
var gotoPage = function (index) {
    var url = webPath + "/crm/1";
    var recordTime = $("#recordTime").val();
    var nextContectTime = $("#nextContectTime").val();
    var customerName = $("#customerName").val();
    var postData = {
        "pageSize": pageSize, "pageNumber": index,
        "customerName": customerName, "recordTime": recordTime, "nextContectTime": nextContectTime
    };
    var options = {"passArguments": index}
    postAjax(url, postData, gotoPageSuccess, options);
};

var gotoPageSuccess = function (result, passArguments) {
    //TODO remove
    result = '{"totalNumber":3,"list":[{"customerId":"33","customerName":"lisi","recordTime":"20160203",' +
    '"nextCallTime":"20150505","contectMan":"Ak","phoneNumber":"12345678911",' +
    '"recordContent":"20150605"}]}';

    var columnList = ["customerId", "customerName", "recordTime", "nextCallTime", "contectMan", "phoneNumber", "recordContent"];
    cleanTableAndPage("contectRecordTable");
    var jsonData = $.parseJSON(result);
    //画table
    $("#contectRecordTable").MakeTable(false, cr_columnData, jsonData.list, tableClass, columnList, cr_operateHtml);
    //画分页
    $("#contectRecordTable").after(comPagination(passArguments, pageSize, jsonData.totalNumber, "gotoPage", "contectRecordP"));

    //Table中操作栏 修改 解锁 查看
    $("#contectRecordTable button").click(function () {
        var that = $(this);
        var customerId = getContectRecordId(that);
        var buttonType = that.val();
        that.val() === "view" ?
            getPage(webPath + "/crm/getViewRecords/" + customerId + "/1.do") :
            alert("something wrong");
    });
}

//查询按钮行为
$('#searchCRecordBtn').click(function () {
    gotoPage(1);
});

//获取id 方便提交 TODO Change
var getContectRecordId = function (that) {
    return that.closest("tr").find("td div")[1].innerHTML;
}